<template>
  <div class='aa-pop'>
    <div class="fg-carInfoBox" v-if="carInfoData!=null">
      <div class="fg-carInfoBox-view">
        <div class='dtbox'>
          <img :src="carInfoData.autoBrandLogo" alt="">
        </div>
        <div class='ddbox'>
          <div class="gs-carInfoBox">{{auto_text}}</div>
          <div class="vinCoda">
            <span>{{vin_text}}</span>
          </div>
        </div>
      </div>
    </div>

    <FrequencyLimitPayment v-if="needPurchaseStatus == 1" :imUserCode="cangpei_param_ucd" @paySuccess="paySuccess" :imConsultantCode="cangpei_param_ccd" :set_price="PurchaseShopVipObj.set_price">
    </FrequencyLimitPayment>

    <div v-if="needPurchaseStatus == -1" class='aa-popBox'>
      <!-- 详细内容 -->
      <div class='aa-popCenter'>
        <div class="ec-categoryOneBox_wrapper">
          <div class="ec-categoryOneBox" v-for="(item,index) in PartsConfig" :key="index">
            <div class='dlbox'>
              <div class='dtbox'>{{item.categoryName}}</div>
              <div class='ddbox'>
                <div v-for="(ite, ins) in item.paramDictionary" :key="ins">
                  {{ite}}
                </div>
                <div class='link lusir-common_cursor' v-if="item.isNeedParam" @click='Rescreenings(item)'>
                  {{item.viewText}}
                </div>
                <template v-if="item.image_action == 'show_transmission_oil_change'">
                  <div class='ec-transBox' @click='goto_transmissionOilViewer(item)' v-if="item.images.length>0">
                    <img class="lusir-common_cursor" :src='item.images[0]' alt="">
                  </div>
                  <div class="seeDetail-view">
                    <div @click='goto_transmissionOilViewer(item)' class="seeDetailBtn lusir-common_cursor">查看详情
                      <img class="button_right_arrow" src='../assets/images/button_right_arrow.png' alt="">
                    </div>
                  </div>
                </template>
                <template v-if="item.image_action == 'show_air_filter_location'">
                  <div class='ec-transBox' @click='goto_airFilterLocationViewer(item)' v-if="item.images.length>0">
                    <img class="lusir-common_cursor" :src="item.images[0]" alt="">
                  </div>
                  <div class="seeDetail-view">
                    <div @click='goto_airFilterLocationViewer(item)' class="seeDetailBtn lusir-common_cursor">查看详情
                      <img class="button_right_arrow" src='../assets/images/button_right_arrow.png' alt="">
                    </div>
                  </div>
                </template>
                <template v-if="item.image_action == 'show_image'">
                  <div class='ec-picBox' v-if="item.images.length>0">
                    <div class="ec-pic_item" v-for="(ites, inde) in item.images" :key="inde">
                      <img :src="ites" @click='loadimg(ites, item.images)' alt="">
                    </div>
                  </div>
                </template>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 筛选参数 -->
    <selectautoparam ref="selectautoparam_instance" @completeChooseParam="completeChooseParam" />

    <transOilParamSelector v-if="transOilParamSelector_launched" :transParamList="transOilParamSelector_params" @close="on_transOilParamSelector_close">
    </transOilParamSelector>
  </div>
</template>

<script>
import { mapState, mapGetters } from "vuex";
import FrequencyLimitPayment from '@/components/FrequencyLimitPayment';
import selectautoparam from '@/components/selectautoparam';
import transOilParamSelector from '@/components/transOilParamSelector';
export default {
  name: '',
  data() {
    return {
      param_vin: this.$com_util.getQueryString("vin"), //VIN码
      param_subid: this.$com_util.getQueryString("subid"), //车型
      carInfoData: null, //车型信息
      auto_text: "", //车型展示文案
      vin_text: "", //VIN码展示文案
      PartsConfig: [], //机油配件参数
      selectautoparam_instance: null, //组件实例
      Rescreening: null,
      needPurchaseStatus: 0,
      PurchaseShopVipObj: {
        needPurchase: false, // 是否需要购买云店VIP
        imConsultantName: "", // 客服名称
        set_price: "" // 查询费
      },
      cachekey: "",

      transOilParamSelector_params: [], //变速箱油参数集合
      transOilParamSelector_launched: false // 变速箱油的多规格选择弹层是否启动
    }
  },
  created() {
    if (this.cangpei_param_ccd) {
      this.NeedPurchaseShopVip();
    } else {
      this.needPurchaseStatus = -1;
    }

    this.getVinParamByVin();
    this.GetAutoPartsConfig();
    console.log('this.needPurchaseStatus', this.needPurchaseStatus);

  },
  methods: {
    // 构造分享代付云店VIP的缓存
    async BuildReplacePayShopVipCache() {
      const res = await this.$imServive({
        url: "/IMUser/BuildReplacePayShopVipCache",
        data: {
          imConsultantCode: this.cangpei_param_ccd
        },
      });
      this.cachekey = res.cachekey;
    },
    // 是否需要购买云店VIP
    async NeedPurchaseShopVip() {
      const res = await this.$imServive({
        url: "/IMUser/NeedPurchaseShopVip",
        data: {
          imConsultantCode: this.cangpei_param_ccd
        },
      });
      this.PurchaseShopVipObj.needPurchase = res.needPurchase;
      this.PurchaseShopVipObj.imConsultantName = res.imConsultantName;
      this.PurchaseShopVipObj.set_price = res.set_price;

      if (this.PurchaseShopVipObj.needPurchase) {
        this.needPurchaseStatus = 1;
        this.BuildReplacePayShopVipCache();
      } else {
        this.needPurchaseStatus = -1;
      }
    },
    paySuccess() {
      this.NeedPurchaseShopVip();
    },
    on_transOilParamSelector_close() {
      this.transOilParamSelector_launched = false;
    },
    //获取精友参数
    async getVinParamByVin() {
      const res = await this.$imServive({
        url: "/Auto/GetJYAutoByVin",
        data: {
          vinCode: this.param_vin,
          autoSubId: this.param_subid
        },
      });
      console.log('resresres', res);

      if (res.length > 0) {
        this.carInfoData = res[0].VinAutoBase;
      } else {
        this.carInfoData = {};
      }
      this.auto_text = this.build_autoText();
      this.vin_text = this.build_vinText();
    },
    //VIN码文案
    build_vinText() {
      return this.param_vin;
    },
    //车型文案
    build_autoText() {
      if (this.param_vin.length > 0) {
        //VIN码请求模式
        if (this.carInfoData) {
          return (
            this.carInfoData.autoBrandName +
            " " +
            this.carInfoData.autoModelName
          );
        } else {
          return "";
        }
      } else {
        //车型请求模式
        if (this.carInfoData) {
          return (
            this.carInfoData.autoBrandName +
            " " +
            this.carInfoData.autoModelName +
            " " +
            this.carInfoData.autoModelSubName
          );
        } else {
          return "";
        }
      }
    },
    async GetAutoPartsConfig() {
      const res = await this.$imServive({
        url: "/Auto/GetAutoPartsConfig",
        isShowLoading: true,
        data: {
          vinCode: this.param_vin,
          autoSubId: this.param_subid,
          userParam: this.Rescreening,
          needAirFilter: true
        },
      });
      this.PartsConfig = res;
    },
    async Rescreenings(data) {
      const res = await this.$imServive({
        url: "/Auto/GetAutoParamListByVin",
        data: {
          VinCode: this.param_vin,
          CategoryIds: data.categoryId,
          autoSubId: this.param_subid
        },
      });
      if (res) {
        this.$refs.selectautoparam_instance.showPopup();
        this.$refs.selectautoparam_instance.setvalue(res, 3, {
          selectData: this.Rescreening
        });
      }
    },
    // 确定选择配件参数
    completeChooseParam(prop) {
      this.$refs.selectautoparam_instance.hidepage();
      let type = prop.type;
      if (type == 3) {
        this.Rescreening = prop.userParam;
      }
      this.GetAutoPartsConfig();
    },
    //查看图片
    loadimg(current, arr) {
      this.$wx.previewImage({
        images: [
          current,
        ],
        closeable: true,
      });
    },
    //查看空调滤网位置
    goto_airFilterLocationViewer(oneItem) {
      this.$router.push({
        path: `/airFilterLocationViewer`,
        query: {
          vin: this.param_vin,
          locid: oneItem.categoryId,
        },
      });
    },
    //查看变速箱油更换
    async goto_transmissionOilViewer(oneItem) {
      const res = await this.$appServive({
        url: "/Auto/GetAutoAdditionalCommand",
        data: {
          vinCode: this.param_vin,
          autoSubId: this.param_subid
        },
      });
      console.log('resres', res);


      //是否需要选车型参数
      let needSelectTransOilParam = false;

      res.commands.forEach(item => {
        if (item.command_text == "transmission_oil_change") {
          needSelectTransOilParam =
            item.command_param_2.toLowerCase() == "true";
          if (item.command_param_3 != "") {
            this.transOilParamSelector_params = JSON.parse(item.command_param_3)
          }
        }
      });

      if (needSelectTransOilParam) {
        this.transOilParamSelector_launched = true
      } else {
        this.$router.push({
          path: `/TransmissionOil`,
          query: {
            skip: 1,
            vin: this.param_vin,
            subid: this.param_subid,
            tid: oneItem.categoryId,
          },
        });
      }
    },
    oilconsumption_close() {
      this.transOilParamSelector_launched = false
    }
  },
  computed: {
    ...mapGetters([
      "cangpei_param_gcd",
      "cangpei_param_ccd",
      "cangpei_param_ucd",
    ])
  },
  components: {
    selectautoparam,
    FrequencyLimitPayment,
    transOilParamSelector
  }
}
</script>

<style scpoed>
/* 弹层通用样式 */
.aa-pop {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: #fff;
}
/* 顶部一层车型logo */
.fg-carInfoBox {
  padding: 0.32rem;
  width: 100%;
  background: #fff;
  box-sizing: border-box;
}
.fg-carInfoBox-view {
  width: auto;
  height: 1.28rem;
  padding: 0.26666666666666666rem 0.28rem;
  background: #f6f6f6;
  display: flex;
  align-items: center;
}
.fg-carInfoBox-view .dtbox {
  width: 1.0666666666666667rem;
  height: 1.0666666666666667rem;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
}
.fg-carInfoBox .dtbox img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}
.fg-carInfoBox .ddbox {
  height: 100%;
  margin-left: 0.24rem;
  flex: 1;
}
.fg-carInfoBox .ddbox .gs-carInfoBox {
  width: 100%;
  height: auto;
  font-size: 0.36rem;
  line-height: 0.64rem;
  color: #282828;
}
.fg-carInfoBox .ddbox .vinCoda {
  width: auto;
  font-size: 0.32rem;
  color: #666;
  display: flex;
  align-items: center;
}
.fg-carInfoBox .ddbox .vinCoda > span {
  font-size: 0.32rem;
  font-weight: normal;
  text-align: left;
  color: #666;
}
/* 顶部一层车型logo */
.aa-popBox {
  width: 100%;
  height: auto;
  overflow: hidden;
  border-radius: 0.21333333333333335rem;
  box-sizing: border-box;
}
.aa-popCenter {
  width: 100%;
  height: calc(100vh - 2.46rem);
  padding: 0 0.32rem;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
}
.ec-categoryOneBox_wrapper {
  width: 100%;
  height: auto;
  background: #fff;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 500;
  border: 2px solid #eee;
  box-sizing: border-box;
}
.ec-categoryOneBox {
  width: 100%;
  height: auto;
}
.ec-categoryOneBox .dlbox {
  display: flex;
  border-bottom: 0.02666666666666667rem solid #eee;
}
.ec-categoryOneBox .dtbox {
  width: 30%;
  padding-right: 0.32rem;
  font-size: 0.36rem;
  text-align: left;
  color: #999;
  word-wrap: break-word;
  background: #f6f6f6;
  padding: 0.32rem;
  display: flex;
  align-items: flex-start;
  border-right: 0.02666666666666667rem solid #eee;
  box-sizing: border-box;
}
.ec-categoryOneBox .ddbox {
  width: 70%;
  font-size: 0.36rem;
  color: #333;
  box-sizing: border-box;
  background: #fff;
  padding: 0.32rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}
.ec-categoryOneBox .ec-picBox {
  width: 70%;
  margin-left: -0.4rem;
  font-size: 0.36rem;
  line-height: 0.64rem;
  text-align: left;
  color: #282828;
}
.ec-categoryOneBox .ec-transBox {
  width: 70%;
  font-size: 0.36rem;
  line-height: 0.64rem;
  text-align: left;
  color: #282828;
  margin-right: 0.4rem;
}
.ec-pic_item {
  width: 1.6rem;
  height: 1.6rem;
  margin: 0 0 0.26666666666666666rem 0.4rem;
  border: 2px solid #e8e8e8;
  border-radius: 0.08rem;
  overflow: hidden;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  float: left;
  clear: none;
}
.ec-picBox img {
  width: 100%;
  object-fit: cover;
  width: 1.6rem;
  height: 1.6rem;
}
.ec-transBox img {
  width: 100%;
  object-fit: cover;
  width: 1.6rem;
  height: 1.6rem;
}
.ec-categoryOneBox .ddbox > div {
  width: auto;
  font-size: 0.32rem;
  font-weight: normal;
  color: #282828;
  display: inline-block;
}
.ec-categoryOneBox .ddbox > div.link {
  width: auto;
  font-size: 0.32rem;
  line-height: 0.64rem;
  text-align: left;
  color: #377de8;
  display: inline-block;
  width: auto;
  font-size: 0.32rem;
  font-weight: normal;
  display: inline-block;
}
.seeDetail-view {
  width: 1.6rem;
  height: 1.6rem;
  margin: 0 0 0.26666666666666666rem 0;
  border-radius: 0.08rem;
  overflow: hidden;
  display: flex !important;
  justify-content: flex-start;
  align-items: center;
}
.seeDetailBtn {
  background-color: #e74c3c;
  color: #fff;
  font-size: 0.28rem;
  padding: 0.08rem 0.16rem;
  border-radius: 0.08rem;
  display: flex;
  justify-content: center;
  align-items: center;
  white-space: nowrap;
}
.button_right_arrow {
  width: 0.08rem;
  height: 0.12rem;
  margin-left: 0.05333333333333334rem;
}
</style>
